<template>
  <div>
    <b-alert
      dismissible variant="danger"
      :show="showAlert" @dismissed="showAlert=false"
    >数据加载失败</b-alert>
    <b-card class="luke-table-lg">
      <b-row slot="header">
        <h3 class="luke-table-heading">用户信息</h3>
        <b-button variant="primary" class="luke-table-refresh" @click="refresh">
          刷新
        </b-button>
      </b-row>
      <b-table
        striped bordered responsive show-empty
        :items="items" :fields="fields"
      >
        <template slot="empty">
          <p class="luke-loading-text">加载中...</p>
        </template>
      </b-table>
    </b-card>
  </div>
</template>

<script>
  import Config from '@/assets/global-config'
  import axios from 'axios'
  export default {
    name: 'UserInfo',
    data () {
      return {
        fields: {
          col0: { label: 'ID', variant: 'danger' },
          col1: { label: '昵称', variant: 'danger' },
          col2: { label: '金额', variant: 'danger' },
          col3: { label: '介绍人', variant: 'danger' },
          col4: { label: '历史下注输赢金额', variant: 'success' },
          col5: { label: '历史大老板输赢', variant: 'success' },
          col6: { label: '历史坐庄输赢', variant: 'success' },
          col7: { label: '历史坐庄次数', variant: 'info' },
          col8: { label: '开散盘次数', variant: 'info' },
          col9: { label: '开庄盘次数', variant: 'info' },
          col10: { label: '大老板下注总金额', variant: 'warning' },
          col13: { label: '近10局输赢', variant: 'warning' },
          col12: { label: '可提佣总金额', variant: 'warning' },
          col11: { label: '可提佣人数' },
          col14: { label: '今日坐庄次数' },
          col15: { label: '进入房间次数' },
          col16: { label: '是否连续三天登录' },
          col17: { label: '最大下注金额' }
        },
        items: [],
        showAlert: false
      }
    },
    created () {
      this.fetchData()
    },
    methods: {
      fetchData () {
        let originData = this.items
        this.items = []
        var that = this
        axios.post(Config.user_info_action())
        .then(function (response) {
          that.showAlert = false
          that.items = response.data
        })
        .catch(function (error) {
          console.log(error)
          that.showAlert = true
          that.items = originData
        })
      },
      refresh () {
        this.fetchData()
      }
    }
  }
</script>
